import time

from common.shop_tuiguang import shop_tuiguang

class TG_testcase:
    def __init__(self):
        self.m=shop_tuiguang()
        self.m.h_login("admin","123456")
    def managecase1(self,li):
        newli=[]##定义一个新列表接受切割的元素
        steplis=li[4].split("\n")##把数据分割成一行
        for i in range(len(steplis)):
            k= steplis[i].split("=")##通过等号分割数据
            newli.append(k[1])##把等号后面的数据加入到定义的列表
        wd = self.m.shop_add(newli)
        time.sleep(0.5)
        a,b="",""
        try:
            a=wd.find_element_by_class_name("invalid-msg").text##捕获失败后的界面的元素
            if a=="":
                a="添加失败"
        except:
                b= "添加成功！"
        print(a,b)
        result = ''
        # if li[5] in a or li[5] in b:
        #     result="%s--Test pass"%li[0]
        # else:
        #     result="%s--Test fail"%li[0]
        if li[5] in b:
            result="%s--Test pass"%li[0]
        elif li[5] in a:
            result="%s--Test failed"%li[0]
        with open("../TestReport/GUI测试报告.xls","a+") as f:        #把结果输出到表格中
            f.writelines(result+"\n")
if __name__ == "__main__":
    k=TG_testcase()